package cn.stylefeng.guns.modular.business.timer;

import cn.stylefeng.guns.modular.business.frequency.transport.entity.Transport;
import cn.stylefeng.guns.modular.business.frequency.transport.mapper.TransportMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @Author jzy
 * @Date 2020/10/28 0028
 **/
@Component
public class LogisticsTask {

    @Resource
    private TransportMapper transportMapper;

    private Logger logger = LoggerFactory.getLogger(LogisticsTask.class);

    /**
     * 每天0点05分执行
     */
    @Scheduled(cron = "0 05 0 * * ? ")
    public void logisticsStatusUpdate() {
        logger.info("开始执行物流跟踪状态修改任务---------------------------------");
        // 查询已跟踪的运单
        List<Transport> list = transportMapper.selectList(new QueryWrapper<Transport>().lambda()
        .eq(Transport::getLogisticsStatus, 1));
        if (list != null && list.size() > 0) {
            List<Long> ids = list.stream().map(Transport::getId).collect(Collectors.toList());
            transportMapper.updateLogisticsStatusBatchIds(ids);
        }
        logger.info("物流跟踪状态修改任务执行完毕----------------------------------");
    }

}
